from main.model.logic.interruption import Interruption, InterruptionManager, TimeOutHandler, IORequestHandler, IOFinishedHandler,\
    KillHandler, ExecuteHandler

class InterruptionManagerBuilder(object):
    
    def __init__(self):
        self.__routines = {}
    
    def with_kernel(self, kernel):
        self.__kernel = kernel
        return self
    
    def with_defaults(self):
        self.__routines[Interruption.TIME_OUT]     = TimeOutHandler()        
        self.__routines[Interruption.IO_REQUEST]   = IORequestHandler()
        self.__routines[Interruption.IO_FINISH]    = IOFinishedHandler()
        self.__routines[Interruption.KILL_PROCESS] = KillHandler()
        self.__routines[Interruption.EXECUTE]      = ExecuteHandler()
        return self
        
    def with_routines(self, kind, handler):
        self.__routines[kind] = handler
        return self
    
    def build(self):
        return InterruptionManager(self.__kernel, self.__routines)

    def get_default(self, kernel):
        return self.with_kernel(kernel).with_defaults().build()


